<?php

$data = get_region_info($id);
if($id == 0){
	$data[0]['status'] = 'open';
	$data[0]['children'] = get_region_info($data[0]['id']);
}else if($_user_type >= 3){
	$odata = $data;
	unset($data);
	$data[0] = array(
		'id' => $id,
		'name' => get_root_region_name($id),
		'status' => 'open',
		'child' => count($odata),
		'children' => $odata
	);
}
echo array2json($data, true);
exit();

function get_region_info($id){
	global $db;
	$data = array();
	$query = $db->query("select id,name from design_category  where parent_id='$id'");
	while($row = $db->fetch_array($query)){
		$row['status'] = 'close';
		$row['child'] = intval($db->result_first("select count(*) from design_category  where parent_id='{$row['id']}'"));
		$data[] = $row;
	}
	return $data;
}

function get_root_region_name($id){
	global $db;
	return $db->result_first("select name from design_category  where id='$id'");
}

?>
